#define _CRT_SECURE_NO_WARNINGS 1

#include<iostream>
#include<algorithm>
#include<vector>

using namespace std;

const int N = 100010;

int n;

int main()
{
    scanf("%d", &n);
    int l, r;
    vector<pair<int, int>> v;
    for (int i = 0; i < n; i++)
    {
        scanf("%d%d", &l, &r);
        v.push_back({ l,r });
    }

    sort(v.begin(), v.end(), [](pair<int, int> a, pair<int, int> b) {
        return a.second < b.second;
        });

    int res = 0, ed = -2e9;
    for (int i = 0; i < n; i++)
    {
        if (v[i].first > ed)
        {
            res++;
            ed = v[i].second;
        }
    }
    cout << res << endl;
    return 0;
}